package com.lbi.framework.view {
	import com.lbi.animation.animator.Animator;
	import com.lbi.animation.util.Engine;
	import com.lbi.debug.Log;
	import com.lbi.debug.LogType;
	
	import asunit.framework.TestCase;		public class AnimatorTest extends TestCase {
		private var animated : Object;//ViewBase; 
	
		private var animator : Animator;
	
		private var MORE_FRAMES_THAN_WILL_BE_IN_A_DEFAULT : Number = 100;
	
		private var START_VALUE : Number = 100;
		
		public function AnimatorTest() {
			super();
		}

		override protected function setUp() :void{
			animated = new Object();
			animated._alpha = START_VALUE;
			animator = new Animator(animated);
			//animator._alpha = START_VALUE;
		}
		override protected function tearDown() :void{
			animated = null;
			animator = null;
		}
		public function testNormalProperties() : void{
			var target_alpha : Number = START_VALUE - 100;
			animator._alpha = target_alpha; // this is what should trigger an animation.
			Engine.advanceFrames(1); // force a frame of the animation
			assertTrue("animation should have started:" +
						"_alpha = "+ animated._alpha ,
						animated._alpha>0 && animated._alpha < 100);
			Engine.advanceFrames(MORE_FRAMES_THAN_WILL_BE_IN_A_DEFAULT);
			assertEquals("should continue to the final value",
						target_alpha, animated._alpha);
		}
		public function testDirectAccessDoesNotBreak() :void{
			animator._alpha = 0; // start animation
			Engine.advanceFrames(3);
			var direct_target : Number = 100;
			animated._alpha = 100; // directly access property on animated
			Engine.advanceFrames(MORE_FRAMES_THAN_WILL_BE_IN_A_DEFAULT);
			assertEquals(direct_target,animated._alpha);
		}
//		/**
//		 * it would be better to throw an error if an unregistered property is accessed
//		 * but for now... I guess it's just gonna have to silently fail.
//		private function testForcesRegistrationOfSpecialProperties() :void {
//			Log.clear();
//			animator.special_property = 230;
//			assertEquals(LogType.ERROR,Log.getLastMessageType());
//			Log.clear();
//			animator.registerProperty("special_property");
//			animator.special_property = 230;
//			assertNotNull(animated.special_property);
//		}
//		 */
//		public function testDirectAccessOfAccessorPropertiesDoesNotBreak() :void{
//			animator._alpha = 0;
//			Engine.advanceFrames(2);
//			var direct_target : Number = 200;
//			animated._alpha = direct_target;
//			Engine.advanceFrames(MORE_FRAMES_THAN_WILL_BE_IN_A_DEFAULT);
//			assertEquals(direct_target,animated._alpha);
//		}


	
		public function testSetPropertiesWithChaining() :void{
			animator._alpha = START_VALUE;
			assertNotNull(animator.change("_alpha"));
			assertEquals("_alpha",animator.change("_alpha").property);
			var frames : Number = MORE_FRAMES_THAN_WILL_BE_IN_A_DEFAULT;
			assertEquals("checking frame count can be chained through",
							frames,
							animator.change("_alpha").setFrames(frames).frames);
			var easing : Function = function(v:Number):Number {return v;};
			assertSame("easing function should be passed through",
							easing,
							animator.change("_alpha").setEasing(easing).easing);
		}
		public function testInterruption() : void{
			animator._alpha = 0;
			Engine.advanceFrames(4);
			animator._alpha = 100;
			Engine.advanceFrames(MORE_FRAMES_THAN_WILL_BE_IN_A_DEFAULT);
			assertEquals("should have returned to _alpha=1 after interrupted",100,animated._alpha);
		}

	
	}
}